package com.xunker.appointment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xunker.appointment.exception.AppointmentException;
import com.xunker.appointment.mapper.HospitalSetMapper;
import com.xunker.appointment.model.hospital.HospitalSet;
import com.xunker.appointment.result.ResultCodeEnum;
import com.xunker.appointment.service.HospitalSetService;
import com.xunker.appointment.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

@Service
//不需要实现重写
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
    @Override
    public String getSignKey(String hospitalCode) {
        QueryWrapper<HospitalSet> wrapper=new QueryWrapper<>();
        wrapper.eq("hospital_code",hospitalCode);
        final HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        if (hospitalSet!=null){
            return hospitalSet.getSignKey();
        }
        return null;
    }

    @Override
    public SignInfoVo getSignInfoVo(String hospitalCode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hospital_code",hospitalCode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        if(null == hospitalSet) {
            throw new AppointmentException(ResultCodeEnum.HOSPITAL_OPEN);
        }
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;
    }
}
